package bs.app.Res;

import bs.app.android.Image;

public class CRess 
{
	// cho Page 1
	public static Image Logo;
	public static Image imgTitle;
	public static Image imgBanner_back;
	public static Image [] imgDotted;
	public static Image footer_back;
	public static Image background;
	public static Image[][] IconApp;
	public static Image imgFocus;
	// cho Page 2
	public static Image texticon;
	public static Image textborder_left;
	public static Image textborder_midle;
	public static Image textborder_right;
	public static Image[] imgloading;
	public static Image download;
	public static Image imgrating;
	public static Image Money;
	public static Image[] scrollbar;
	public static Image scrollpoint;
	///////////////////////
	public static Image arrow;
	public static Image menuchosen;
	public static Image menuchosen1;
	public static Image menuitem;
	public static Image menubar;
	public static Image dialog;
	public static Image search;
	public static Image keyboard;
	public static Image card;
	public static Image smallrow;
	public static void ImgLoading()
	{
		try {
			if(imgloading==null)
			{
				imgloading=new Image[12];
				for(int i=0;i<imgloading.length;i++)
				{
					imgloading[i]=Image.createImage("/loadinfo_layer"+i+".png");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static void LoadDialog()
	{
		
		try {
			if(card == null) card = Image.createImage("/card.png");
			if(keyboard == null)keyboard = Image.createImage("/keyboard.png");
			dialog=Image.createImage("/dialogbox.png");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static void LoadLogo()
	{
		try {
			Logo=Image.createImage("/logo.png");
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static void ClearLogo()
	{
		Logo=null;
		System.gc();
	}
	public static void LoadSubMenu()
	{
		try {
			menuchosen=Image.createImage("/menuchosen.png");
			menuchosen1 =Image.createImage("/menuchosen1.png");
			menuitem=Image.createImage("/menuitem.png");
			arrow=Image.createImage("/arrow.png");		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void LoadAppPage1(int element,int colum,String[] imageName,Image[] imgserver,String[] MarkLoadImg)
	{
            ClearAppScreen();
		try {
			if(background==null)
				background = Image.createImage("/background.png");
			if(imgTitle == null)
				imgTitle = Image.createImage("/logo_itop.png");
			if(imgBanner_back == null)
				imgBanner_back = Image.createImage("/banner_back.png");
			if(imgDotted == null){
				imgDotted = new Image[3];
				for(int i=0; i < imgDotted.length; i++)
					imgDotted[i] = Image.createImage("/dotted"+(i+1)+".png");
			}
			
			if(footer_back==null)
				footer_back=Image.createImage("/footer_back.png");
			if(menubar==null)
				menubar=Image.createImage("/menubar.png");
			if(imgFocus==null)
				imgFocus=Image.createImage("/focus.png");
			if(search==null)
				search=Image.createImage("/search.png");
			if(keyboard == null)
				keyboard = Image.createImage("/keyboard.png");
			if(card == null)
				card = Image.createImage("/card.png");
			int row=element/colum;
			if(element%colum!=0)
				row++;
			if(IconApp==null)IconApp=new Image[row][colum];
			
			if(imgserver==null)
			{
				for(int i=0;i<element;i++)
				{
					IconApp[i/colum][i%colum]=Image.createImage("/"+imageName[i]);
				}
			}
			else if(imgserver!=null)
			{
				int indexImage=0;
				for(int i=0;i<element;i++)
				{
					if(MarkLoadImg[i].equals("0"))
					{
						IconApp[i/colum][i%colum]=Image.createImage("/"+imageName[i-indexImage]);
					}
					else if(MarkLoadImg[i].equals("1"))
					{
						IconApp[i/colum][i%colum]=imgserver[indexImage];
						indexImage++;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static void ClearAppScreen()
	{
		imgFocus=null;
		IconApp=null;
		System.gc();
	}
	public static void LoadImagePage2(Image[] img)
	{
            ClearAppScreen();
		try {
			if(card == null) card = Image.createImage("/card.png");
			if(keyboard == null)keyboard = Image.createImage("/keyboard.png");
			if(texticon==null)texticon=Image.createImage("/texticon.png");
			if(textborder_left==null)textborder_left=Image.createImage("/textborder_left.png");
			if(textborder_midle==null)textborder_midle=Image.createImage("/textborder_midle.png");
			if(textborder_right==null)textborder_right=Image.createImage("/textborder_right.png");
			if(imgFocus==null)imgFocus=Image.createImage("/chosensub.png");
			if(download==null)download=Image.createImage("/down.png");
			if(imgrating==null)imgrating=Image.createImage("/rating.png");
			if(IconApp==null)IconApp=new Image[img.length][1];
			if(Money==null)Money=Image.createImage("/money.png");
			if(scrollbar==null){
				scrollbar = new Image[3];				
				scrollbar[0]=Image.createImage("/scroll_top.png");
				scrollbar[1]=Image.createImage("/scroll_midle.png");
				scrollbar[2]=Image.createImage("/scroll_bottom.png");
			}
			if(scrollpoint==null)scrollpoint=Image.createImage("/scrollpoint.png");
			if(smallrow==null)smallrow=Image.createImage("/smallarrow.png");
			for(int i=0;i<IconApp.length;i++)
			{
				IconApp[i][0]=img[i];
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
